<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript">
    $().ready(function() {
        view(1);
        /* 조회버튼 */
        $("#btnSearch").bind("click",function(){       
            view(1);
        });

        $("#cancelBtn").bind("click",function(){       
            self.close();
        });  

        $("#confirmBtn").bind("click",function(){
            var orderNum = $("#ordNumTmp").val();
            var orderNo1 = $("#ordNo1Tmp").val();
            var orderNo2 = $("#ordNo2Tmp").val();
            var ordPseq  = $("#ordPseqTmp").val();
            var mawb     = $("#mawbTmp").val();
            var hawb     = $("#hawbTmp").val();
            var clearNo  = $("#clearNoTmp").val();
            
            if(orderNum==null   || orderNum=="") {   alert("Row selected!!"); return false; }
            opener.view(orderNum, orderNo1, orderNo2, ordPseq, mawb, hawb, clearNo );
            self.close();
        });
        
    });

    function view(page){
        $.post(
                '/mawbHawbNumPopView.json', {
                paging : page,
                listScale : "5",
                searchVal : $("#searchVal").val(),
                menuType : $("#menuType").val(),
                searchSelect : $("#searchSelect").val(),
                searchValue : $("#searchValue").val()
               },
            function(data) {
                searchDataMaping(data);    //DATA맵핑 
            });
    }
    
    /* searchData 맵핑 */
    function searchDataMaping(data){
           
        var contents = "";
        var cHeader = "<tr>"
	        +"<th width='10%'>No</th>"
	        +"<th width='15%'>Order No</th>"
	        +"<th width='30%'>MAWB</th>"
	        +"<th width='30%'>HAWB</th>"
        <c:if test="${menuType eq 'CLEARANCE'}">
            +"<th width='15%'>CLEAR DATE</th>"
        </c:if>
        <c:if test="${menuType eq 'MOVEMENT'}">
            +"<th width='15%'>W/H DATE</th>"
        </c:if>
       <c:if test="${menuType eq 'STOCKIN'}">
            +"<th width='15%'>Stock In Date</th>"
        </c:if>
            
            +"</tr>";
        
        $("#orderNumDetail tr").remove();
        
        if(data.resultList.length == 0){
	        <c:if test="${menuType eq 'CLEARANCE' || menuType eq 'MOVEMENT' || menuType eq 'STOCKIN'}">
	            contents = "<tr><td colspan='5' height='50' bgcolor='#FFFFFF' align='center'><B>No Data</B></td></tr>";
	        </c:if>
	        <c:if test="${menuType ne 'CLEARANCE' && menuType ne 'MOVEMENT' && menuType ne 'STOCKIN'}">
	            contents = "<tr><td colspan='4' height='50' bgcolor='#FFFFFF' align='center'><B>No Data</B></td></tr>";
	        </c:if>
	            $("#orderNumDetail").html(cHeader+contents);
            
            
        }else{
	        $.each(data.resultList, function(index){  // List로 받아온값 (여러건)
	           contents += '<tr onclick="rowSelect(this, \''+this.ordNum+'\',\''+this.ordNo1+'\',\''+this.ordNo2+'\',\''+this.ordPseq+'\',\''+this.mawb+'\', \''+this.hawb+'\',\''+this.clearNo+'\');" style="cursor:pointer"><td align="center">'+(index+1)+'</td>'
	               +'<td align="center">'+this.ordNum+'</td>'
	               +'<td align="center">'+this.mawb+'</td>'
	               +'<td align="center">'+this.hawb+'</td>';
	               if($("#menuType").val() == "CLEARANCE" || $("#menuType").val() == "MOVEMENT" || $("#menuType").val() == "STOCKIN" ){
	            	   contents +='<td align="center">'+this.clearDate+'</td>';   
	               }
	               
	               contents += '</tr>';
	        });
	        
        }
        var totalPage = Math.ceil(parseInt(data.mawbHawbNumCount)/parseInt(5));        
        $("#spanCount").empty().html("Total : "+data.mawbHawbNumCount);
        $("#pageCount").empty().html("Page : "+$("#pageNum").val()+" / "+totalPage);            
        $("#page").empty().html(data.pageSplit);
        
        $("#orderNumDetail").html(cHeader+contents);  // 조회 값 뿌리기
        
    }   

    function ajaxPageSplit(num) {
        $("#pageNum").val(num);
        view(num);
    }

    function rowSelect(obj, ordNum, ordNo1, ordNo2, ordPseq, mawb, hawb, clearNo){
        $("#ordNumTmp").val(ordNum);
        $("#ordNo1Tmp").val(ordNo1);
        $("#ordNo2Tmp").val(ordNo2);
        $("#ordPseqTmp").val(ordPseq);
        $("#mawbTmp").val(mawb);
        $("#hawbTmp").val(hawb);
        $("#clearNoTmp").val(clearNo);
        
        $("#orderNumDetail tr").css("backgroundColor","#FFFFFF");
        obj.style.backgroundColor="#e0eeee";  
        document.ondblclick=dblclick;
    }
    
    function dblclick(){
        $("#confirmBtn").click(); 
    }
</script>
</head>
<body>

<input type="hidden" id="menuType" value="<c:out value="${menuType}" />" />
<c:if test="${menuType eq 'CLEARANCE' || menuType eq 'MOVEMENT' || menuType eq 'STOCKIN'}">
   <div class="wrapP4">    
</c:if>
<c:if test="${menuType ne 'CLEARANCE' && menuType ne 'MOVEMENT' && menuType ne 'STOCKIN'}">
    <div class="wrapP3">
</c:if>
    <div class="pagetitle">
        <h1>MAWB / HAWB</h1>
    </div>
    <div>
        <table class="TableST">
            <tr>
                <th>MAWB / HAWB</th>
                <td>
                    <input type="text" class="inST" name="searchVal" id="searchVal"/>
                </td>
            </tr>
            <tr>
                <th>SHIPPER / MESSRS</th>
                <td>
                    <select name="searchSelect" id="searchSelect"><option value="">--select--</option><option value="SHIPPER">SHIPPER</option><option value="MESSRS">MESSRS</option></select>
                    <input type="text" class="inST" name="searchValue" id="searchValue"/>
                </td>
            </tr>
        </table>
        <DIV class="bo_btnS">
            <ul class="btnst"><li class="a"><a href="#" id="btnSearch" >SEARCH</a></li></ul>
        </DIV>
        <br /><br /><br /><br />
        <ul>
            <li class="totaltext"><span id="spanCount">Total : 0</span></li>
            <li class="pagetext"><span id="pageCount">Page : 1&frasl;1</span></li>
            <li class="bolistW">
                <table class="TableST4" id="orderNumDetail">
                   
                </table>
            </li>
        </ul>
    </div>
    <div class="page_wrap">
        <div class="page" id="page" >
        </div>
    </div>
    <div class="bo_btn">
        <ul class="btnst"><li class="a"><a href="#" id="confirmBtn" >CONFIRM</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="cancelBtn" >CANCEL</a></li></ul>
    </div>
    <input type="hidden" name="pageNum" id="pageNum" value="1">
    <input type="hidden" name="ordNumTmp" id="ordNumTmp"/>
    <input type="hidden" name="ordNo1Tmp" id="ordNo1Tmp"/>
    <input type="hidden" name="ordNo2Tmp" id="ordNo2Tmp"/>
    <input type="hidden" name="ordPseqTmp" id="ordPseqTmp"/>
    <input type="hidden" name="mawbTmp" id="mawbTmp"/>
    <input type="hidden" name="hawbTmp" id="hawbTmp"/>
    <input type="hidden" name="clearNoTmp" id="clearNoTmp"/>
</div>
</body>
</html>